<?php
namespace app\api\controller;
use app\common\controller\Api;

/**
 *优惠券
 */
class Coupon extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];



    /**
     * 个人中心--我的卡券
     *
     * @param $status int 状态:0=全部,1=未使用,2=已使用,3=已失效
     */
    public function getUserCouponPageList(\app\common\model\UserCouponModel $UserCouponModel, \app\api\validate\CouponValidate $CouponValidate)
    {
        $params = $this->request->post();
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',10);
        if(!$CouponValidate->check($params,[],'getUserCouponPageList')){
            $this->errorReturn(40001,$params,$CouponValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $UserCouponModel->getUserCouponPageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 领券中心--获取可领取优惠券
     *
     * @param $use_type string 使用位置:mini=小程序,pc=PC
     * @param $page int 页码
     * @param $limit int 每页数据
     */
    public function getCouponPageList(\app\common\model\CouponModel $CouponModel, \app\api\validate\CouponValidate $CouponValidate)
    {
        $params = $this->request->post();
        if(!$CouponValidate->check($params,[],'getCouponPageList')){
            $this->errorReturn(40001,$params,$CouponValidate->getError());
        }
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',10);
        $user_id = $this->auth->id;
        $return = $CouponModel->getCouponPageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 领券中心--领取优惠券
     *
     * @param $coupon_id int 优惠券ID
     */
    public function drawCoupon(\app\common\model\CouponModel $CouponModel, \app\api\validate\CouponValidate $CouponValidate)
    {
        $params = $this->request->post();
        if(!$CouponValidate->check($params,[],'drawCoupon')){
            $this->errorReturn(40001,$params,$CouponValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $CouponModel->drawCoupon($params,$user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


    /**
     * 个人中心--我的兑换券
     *
     * @param int $status 状态:0=全部,1=未使用,2=已使用,3=已失效
     */
    public function getUserCouponExchangePageList(\app\common\model\UserCouponExchangeModel $UserCouponExchangeModel, \app\api\validate\CouponValidate $CouponValidate)
    {
        $params = $this->request->post();
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',10);
        if(!$CouponValidate->check($params,[],'getUserCouponExchangePageList')){
            $this->errorReturn(40001,$params,$CouponValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $UserCouponExchangeModel->getUserCouponExchangePageList($params,$user_id,$page,$limit);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }


}